package com.example.sunyueproject;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.Toast;

public class MainActivity extends Activity {
	
    private CameraPreview camera_preview;
    private ImageButton recordButton;
    private boolean isRecording = false;
	
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Create an instance of Camera
        if(!CameraControl.init()) {
        	prompt("no camera available");
        	return;
        }
        
        // Set camera parameters
        CameraControl.adjust();

        // Create our Preview view and set it as the content of our activity.
        camera_preview = new CameraPreview(this);
        FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
        preview.addView(camera_preview);
        
        recordButton = (ImageButton) findViewById(R.id.record);
        recordButton.setOnClickListener(
            new View.OnClickListener() {
                public void onClick(View v) {
                    if (!isRecording) {
                       FrameCollector fc = new FrameCollector();
                       //CameraControl.setCallback(fc);
                       	CameraControl.startRecorder(camera_preview.getHolder());
                        isRecording = true;
                    } else {
                    	CameraControl.stopRecorder();
                    	isRecording = false;
                    }
                }
            }
        );
    }

    
    public void prompt(String info) {
    	Toast.makeText(this, info, Toast.LENGTH_SHORT).show();
    }
}